package com.zhongyi.http.service.impl;

import java.util.List;
import java.util.Map;

import com.zhongyi.db.DBManager;
import com.zhongyi.entity.Company;
import com.zhongyi.entity.Contact;
import com.zhongyi.http.service.MessageService;

public class MessageServiceImpl implements MessageService {
	
	public DBManager dbManager ;
	
	public void setDbManager(DBManager dbManager) {
		this.dbManager = dbManager;
	}

	@Override
	public void addCompany(String insert, Company corp) {
		// TODO Auto-generated method stub
		dbManager.insertToDB(insert, new Object[]{corp.getId(),corp.getCorp_name(),corp.getArea_id(),corp.getAdress(),corp.getOrigin_site(),corp.getHome_page(),corp.getCorp_level(),corp.getCorp_type(),corp.getLinker(),corp.getKeyword(),corp.getCreate_time(),corp.getRemark()});
	}

	@Override
	public List getAllCompany() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addContact(String insert, Contact contact) {
		// TODO Auto-generated method stub
		dbManager.insertToDB(insert, new Object[]{contact.getId(),contact.getCorp_id(),contact.getContact_info(),contact.getInfo_type(),contact.getRemark(),contact.getCreate_time()});
	}

	@Override
	public int getComanyCount(String countSQL , String corpName) {
		// TODO Auto-generated method stub
		Long result = new Long(0);
		Map map = dbManager.queryForMap(countSQL, new Object[]{corpName.trim()});
		if(map != null && map.get("total") != null){
			result = (Long)map.get("total"); 
		}
		return result.intValue();
	}
	

}
